import Vue from 'vue'
import moment from 'moment'
import 'moment/locale/zh-cn'

/**
 * @description 格式化时间
 * @example 2020-03-28T01:54:26.000Z => 2020-03-28 01:54:26
 */
Vue.filter('formatDate', function(value) {
  if (!value) return ''
  value = value.toString()
  const arr = value.split('T')
  return arr[0] + ' ' + arr[1].substr(0, 8)
})

Vue.filter('datetime', function(value) {
  if (!value) return ''
  value = value.toString()
  const arr = value.split('T')
  return arr[0] + ' ' + arr[1].substr(0, 8)
})

Vue.filter('shortDatetime', function(value) {
  return moment(value).fromNow()
})
